package com.yidu.ladder.base.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.ladder.base.domain.Bus;
import com.yidu.ladder.base.domain.BusVo;
import com.yidu.ladder.base.domain.Subset;
import com.yidu.ladder.base.service.BusService;
import com.yidu.ladder.util.IDGenerator;

/**
 * 班车控制器
 * 
 * @author yy
 * @since 2019-12-2
 *
 */
@Controller
@RequestMapping("/base")
public class BusController {

	/**
	 * 关联班车业务逻辑层
	 */
	@Autowired
	private BusService busService;

	public BusService getBusService() {
		return busService;
	}

	public void setBusService(BusService busService) {
		this.busService = busService;
	}

	/**
	 * 查询所有班车
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "busAll")
	public List<Bus> findAllBus() {
		return busService.findAllBus();

	}

	/**
	 * 管理页面
	 * 
	 * @return 班车管理页的URL
	 */
	@RequestMapping(value = "bus")
	public String bus() {
		return "base/bus/bus";
	}

	/**
	 * 检索班车
	 * 
	 * @param userVo 班车包装类
	 * @return 班车信息数据
	 */
	@ResponseBody
	@RequestMapping(value = "buss", method = RequestMethod.GET)
	public Map<String, Object> queryBus(BusVo busVo) {
		// 执行分页查询班车方法
		Map<String, Object> busMap = busService.queryBusByCriteriaWithPage(busVo);
		// 返回结果
		return busMap;
	}

	/**
	 * 添加班车
	 * 
	 * @param bus 班车
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "bus", method = RequestMethod.POST)
	public int addBus(Bus bus) {
		bus.setBusId(IDGenerator.getId());
		bus.setRouteId(IDGenerator.getId());
		bus.setStaffId(IDGenerator.getId());
		bus.setSubsetId(IDGenerator.getId());
		bus.setUseable("Y");
		// 执行添加班车方法
		int insert = busService.addBus(bus);
		// 返回结果
		return insert;

	}

	/**
	 * 修改班车
	 * 
	 * @param bus 班车
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "bus", method = RequestMethod.PUT)
	public boolean updateBus(Bus bus) {
		// 执行修改班车方法
		boolean updateBus = busService.updateBus(bus);
		// 返回结果
		return updateBus;

	}

	/**
	 * 冻结或还原班车
	 * 
	 * @param busId   班车Id
	 * @param useable 是否可用
	 * @return
	 */
	@RequestMapping(value = "bus", method = RequestMethod.DELETE)
	@ResponseBody
	public boolean frozenOrRecoveBus(String busId, String useable) {
		// 执行冻结或换车班车方法
		boolean result = busService.frozenOrRecoveBus(busId, useable);
		// 返回结果
		return result;
	}

	/**
	 * 获取下拉框的值
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "busCar")
	public List<Subset> selectAllBus() {
		return busService.selectAllBus();
	}
}
